package com.wkbb.basic.thread;

import com.wkbb.basic.enums.DeviceBoxOperateTypeEnum;
import com.wkbb.basic.service.DeviceBoxService;
import lombok.extern.slf4j.Slf4j;

/**
 * 巨龙盒子操作异步处理
 * */
@Slf4j
public class DeviceBoxTask implements Runnable{

    private Integer operateType;
    private DeviceBoxService deviceBoxService;
    private String personId;
    private String picUrl;
    private Long orgId;

    public DeviceBoxTask(Integer operateType,DeviceBoxService deviceBoxService,String personId, String picUrl,Long orgId) {
        this.deviceBoxService = deviceBoxService;
        this.operateType = operateType;
        this.personId = personId;
        this.picUrl = picUrl;
        this.orgId = orgId;
    }

    @Override
    public void run() {
        try {
            log.info("巨龙盒子操作异步处理.....start，personId:{}，picUrl:{}", personId, picUrl);
            Thread.sleep(1000);
            if(operateType == DeviceBoxOperateTypeEnum.BOX_OPERATE_ADD_PERSON.getCode().intValue())
            {
                log.info("******DeviceBoxTask addBoxPerson begin****");
                deviceBoxService.addBoxPerson(personId, picUrl);
                log.info("******DeviceBoxTask addBoxPerson end****");
            }
            else if(operateType == DeviceBoxOperateTypeEnum.BOX_OPERATE_DELETE_PERSON.getCode().intValue())
            {
                log.info("******DeviceBoxTask deleteBoxPerson begin****personId:{},orgId:{}",personId,orgId);
                deviceBoxService.deleteBoxPerson(personId,orgId);
                log.info("******DeviceBoxTask deleteBoxPerson end****");
            }
            log.info("巨龙盒子操作异步处理.....end");
        } catch (Exception e) {
            log.error("巨龙盒子操作异步处理，{}", e);
            e.printStackTrace();
        }
    }
}
